#define TRACE
#include <System.cpu\cpuFalloc.cpp>
#include <System\TreeSet.h>

#include <stdio.h>

using namespace System;
template class TreeSet<int>;

int TreeSet_COMPARE(unsigned __int32 shard, void* x, void* y)
{
	int a = *((int*)x);
	int b = *((int*)y);
    return (a < b ? -1 : (a > b ? 1 : 0));
}

void testTreeSet(fallocHeap* heap)
{
	fallocInit(heap);
	fallocContext* ctx = fallocCreateCtx(heap);
	fallocContext* stack = fallocCreateCtx(heap);
	falloc(stack, 70, false);
	//
	TreeSet<int> treeSet; treeSet.xtor(0, ctx);
	treeSet.Add(5);
	treeSet.Add(3);
	treeSet.Add(1);
	treeSet.Add(2);
	treeSet.Add(7);
	treeSet.Add(10);

	//
	TreeSet<int>::Enumerator e; treeSet.GetEnumerator(e, stack);
	while (e.MoveNext(&treeSet))
		printf("%d\n", e.Current);
	e.Dispose();

	// free and exit
	fallocDisposeCtx(stack);
	fallocDisposeCtx(ctx);
}

void main()
{
	cpuFallocHost fallocHost = cpuFallocInit(2048);
	
	// test
	testTreeSet(fallocHost.heap);

	// free and exit
	cpuFallocEnd(fallocHost);
	printf("done."); char c; scanf_s("%c", &c);
}
